﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraGrid.Views.Grid;
using MINERP.BLL.QC;

using MINERP.COM;

namespace MINERP.QC
{
    public delegate void SelectProductEventHander(string productCode);
    public partial class FrmSelect : Form
    {
        public event SelectProductEventHander SelectProduct;
        public int _techid;
        QCBLL _bll = new QCBLL();
        public FrmSelect()
        {
            InitializeComponent();
        }

        private void dateEdit2_EditValueChanged(object sender, EventArgs e)
        {

        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            if (isHaveSelect())
            {
                DateTime startTime = dtStartTime.Text == string.Empty ? Convert.ToDateTime("1800-1-1 0:00:00") : Convert.ToDateTime(dtStartTime.Text);
                DateTime endTime = dtEndTime.Text == string.Empty ? Convert.ToDateTime("1800-1-1 0:00:00") : Convert.ToDateTime(dtEndTime.Text);
                endTime = endTime.AddDays(1);
                gridControlProducts.DataSource = _bll.GetProductList(cmbShop.Text, txtCustomer.Text, txtProductName.Text, startTime, endTime);
            }
            else
            {
                MessageBox.Show("最少需要一个过滤条件","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            Cursor = Cursors.Default;
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            cmbShop.Properties.DataSource = _bll.GetShops();
        }

        private bool isHaveSelect()
        {
            bool flag = true;
            if (txtCustomer.Text.Trim() == string.Empty && txtProductName.Text.Trim() == string.Empty && cmbShop.Text.Trim() == string.Empty && dtEndTime.Text.Trim() == string.Empty && dtStartTime.Text.Trim() == string.Empty)
            {
                flag = false;
            }
            return flag;
        }

        private void gridViewProducts_DoubleClick(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            GridView view = (GridView)sender;
            if (view.FocusedRowHandle >= 0)
            {
                DataRow dr = gridViewProducts.GetFocusedDataRow();
                if (!dr.IsNull("OrderProductCode"))
                {
                    SelectProduct(dr["OrderProductCode"].ToString());
                    Logoff.ShowMainFrm("检查产品");
                    this.Close();
                    //FrmCheckOrderInfo frmCheckOrderInfo = FrmCheckOrderInfo.GetInstance;
                    //frmCheckOrderInfo.techid = _techid;
                    //frmCheckOrderInfo.txtOrderProductCode.Text = dr["OrderProductCode"].ToString();
                    //frmCheckOrderInfo.btnOk_Click(sender, e);
                    //frmCheckOrderInfo.ShowDialog();
                }
            }
            Cursor = Cursors.Default;
        }

        private void FrmSelect_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                this.Hide();

            }
            //this.Owner = null;
        }
    }
}
